package com.isunland.managesystem.ui;

import android.os.Bundle;
import com.google.gson.Gson;
import com.isunland.managesystem.R;
import com.isunland.managesystem.adapter.MonthAttendanceAdapter;
import com.isunland.managesystem.base.Base;
import com.isunland.managesystem.base.BaseListFragment;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.CurrentUser;
import com.isunland.managesystem.entity.FormDetail;
import com.isunland.managesystem.entity.MonthAttendance;
import com.isunland.managesystem.utils.ParamsNotEmpty;
import com.isunland.managesystem.utils.ToastUtil;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * 对象功能:
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: HuXiaoDan
 * 创建时间: 2017/5/11 13:46
 */
public class MonthAttendanceFragment extends BaseListFragment {
  public static final String EXTRA_ID =
      "com.isunland.managesystem.ui.MonthAttendanceFragment.EXTRA_ID";

  private String id;
  private ArrayList<FormDetail> mList;

  @Override public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setBack(true);
    setTitleCustom(R.string.monthAttendanceDetail);
    id = getArguments().getString(EXTRA_ID);
    mList = new ArrayList<>();
  }

  @Override public String getUrl() {
    return ApiConst.URL_MONTH_ATTENDANCE_DETAIL;
  }

  @Override public HashMap<String, String> getparameters() {
    ParamsNotEmpty params = new ParamsNotEmpty();
    params.put("id", id);
    params.put("memberCode", CurrentUser.newInstance(getActivity()).getMemberCode());
    params.put("type", "mobile");
    return params.getParams();
  }

  @Override public void resolveResponse(String json) {
    MonthAttendance result = new Gson().fromJson(json, MonthAttendance.class);
    if (result.getResult() == Base.SUCCESS && result.getRows() != null) {
      //获取列表成功
      mList.clear();
      mList.addAll(result.getRows());
      MonthAttendanceAdapter mAdapter = new MonthAttendanceAdapter(getActivity(), mList);
      setListAdapter(mAdapter);
    } else {
      ToastUtil.show("获取列表失败");
    }
  }

  public static MonthAttendanceFragment newInstance(String id) {
    Bundle args = new Bundle();
    args.putString(EXTRA_ID, id);
    MonthAttendanceFragment fragment = new MonthAttendanceFragment();
    fragment.setArguments(args);
    return fragment;
  }
}
